/**
* 修改登录密码
*/
import React, { Component } from 'react';
import { View, StyleSheet, Text, Image, TouchableOpacity, ScrollView, TextInput } from "react-native";
import { connect } from 'react-redux';
import { Colors, Dimens, ImageRes } from '../../utils/Assets';
import { create_service } from '../../redux/index.js';
import { Contract } from '../../service/index.js';
import ImagePicker from 'react-native-image-picker'
import { Actions } from 'react-native-router-flux';
import Toast from 'react-native-root-toast';
import { ProgressView } from '../custom/index'
import { getStore } from '../../redux/index.js';
class PersonalModifyLoginPasswordView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            loading: false
        }
        this.userInfo = getStore().getState().auth.userInfo
    }
    componentDidMount() {

    }
    componentWillUnmount() {

    }
    submit() {
        if (!this.password) {
            Toast.show('请输入原密码', { position: Toast.positions.CENTER })
            return
        }
        if (!this.reset_password) {
            Toast.show('请输入新密码', { position: Toast.positions.CENTER })
            return
        }
        if (!this.confirm_reset_password) {
            Toast.show('请输入新确认密码', { position: Toast.positions.CENTER })
            return
        }
        if (this.reset_password != this.confirm_reset_password) {
            Toast.show('两次新密码输入不一致', { position: Toast.positions.CENTER })
            return
        }
        this.setState({ loading: true })
        this.props.dispatch(create_service(Contract.POST_USER_RESET_PASSWORD, { token: this.userInfo.token, password: this.password, reset_password: this.reset_password })).then((res) => {
            if (res) {
                Actions.pop()
            }
            this.setState({ loading: false })
        })
    }
    render() {
        return (
            <View style={styles.container}>
                <ScrollView style={{ flex: 1 }} showsVerticalScrollIndicator={false}>
                    <View style={{ paddingHorizontal: 15, flexDirection: 'row', height: 55, justifyContent: 'center', backgroundColor: "#ffffff", marginTop: 10 }}>
                        <Text style={{ fontSize: 15, color: "#333333", alignSelf: 'center', width: 100 }}>原密码</Text>
                        <View style={{ flex: 1, flexDirection: 'row', alignSelf: 'center' }}>
                            <TextInput style={{ fontSize: 15, color: '#333333', height: 40, flex: 1 }}
                                onChangeText={(text) => {
                                    this.password = text
                                }}
                                placeholderTextColor={'#999999'}
                                underlineColorAndroid={'transparent'}
                                placeholder={'请输入原登录密码'}
                                secureTextEntry={true}
                            />
                        </View>
                        <TouchableOpacity style={{ marginLeft: 10, justifyContent: 'center', }} activeOpacity={0.8} onPress={() => {
                            Actions.forgotPasswordView()
                        }}>
                            <Text style={{ fontSize: 15, color: "#378EFB", alignSelf: 'center' }}>忘记密码</Text>
                        </TouchableOpacity>
                    </View>
                    <View style={{ backgroundColor: Colors.bg_color, height: 1 }}></View>
                    <View style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'center', height: 55, backgroundColor: "#ffffff" }}>
                        <Text style={{ fontSize: 15, color: "#333333", alignSelf: 'center', width: 100 }}>新密码</Text>
                        <View style={{ flex: 1, flexDirection: 'row', alignSelf: 'center' }}>
                            <TextInput style={{ fontSize: 15, color: '#333333', height: 40, flex: 1 }}
                                onChangeText={(text) => {
                                    this.reset_password = text
                                }}
                                placeholderTextColor={'#999999'}
                                underlineColorAndroid={'transparent'}
                                placeholder={'请输入新登录密码'}
                                secureTextEntry={true}
                            />
                        </View>
                    </View>
                    <View style={{ backgroundColor: Colors.bg_color, height: 1 }}></View>
                    <View style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'center', height: 55, backgroundColor: "#ffffff" }}>
                        <Text style={{ fontSize: 15, color: "#333333", alignSelf: 'center', width: 100 }}>确认密码</Text>
                        <View style={{ flex: 1, flexDirection: 'row', alignSelf: 'center' }}>
                            <TextInput style={{ fontSize: 15, color: '#333333', height: 40, flex: 1 }}
                                onChangeText={(text) => {
                                    this.confirm_reset_password = text
                                }}
                                placeholderTextColor={'#999999'}
                                underlineColorAndroid={'transparent'}
                                placeholder={'请输入确认密码'}
                                secureTextEntry={true}
                            />
                        </View>
                    </View>
                    <TouchableOpacity style={{ marginTop: 50, backgroundColor: '#378EFB', justifyContent: 'center', marginHorizontal: 15, paddingVertical: 15, borderRadius: 5 }} activeOpacity={0.8} onPress={() => {
                        this.submit()
                    }}>
                        <Text style={{ fontSize: 15, color: "#ffffff", alignSelf: 'center' }}>完成</Text>
                    </TouchableOpacity>
                </ScrollView>
                <ProgressView show={this.state.loading}></ProgressView>
            </View >
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: Colors.bg_color
    }
});
const ExportView = connect()(PersonalModifyLoginPasswordView);
module.exports.PersonalModifyLoginPasswordView = ExportView
